package cn.com.czpb.client.module.nanning.adapter;

import android.app.Activity;
import android.support.annotation.Nullable;
import android.view.View;
import android.widget.AdapterView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;

import java.util.List;

import cn.com.czpb.client.R;
import cn.com.czpb.client.model.event.CurrentCityEventForMainAndZiXun;
import cn.com.czpb.client.model.event.CurrentSecondCityEvent;
import cn.com.czpb.client.model.news.AreaOtherChannelBean;
import cn.com.czpb.client.module.news.adapter.CityDragAdapter;
import cn.com.czpb.client.utils.LogUtils;
import cn.com.czpb.client.utils.SPUtil;
import de.greenrobot.event.EventBus;

/**
 * Created by 猪猪侠 on 2017/11/7.
 */

public class ChannelCityAdapter extends BaseQuickAdapter<AreaOtherChannelBean,BaseViewHolder> {
    private Activity activity;
    public ChannelCityAdapter(@Nullable List<AreaOtherChannelBean> data, Activity activity) {
        super(R.layout.item_channel_city,data);
        this.activity = activity;
    }

    @Override
    protected void convert(BaseViewHolder helper, final AreaOtherChannelBean item) {
        CityDragAdapter cityDragAdapter = new CityDragAdapter(activity,item.getChild(),1);
        helper.setAdapter(R.id.city_channel_item_draggridview,cityDragAdapter);
        helper.setText(R.id.city_channel_item_tv,item.getName());
        helper.setOnItemClickListener(R.id.city_channel_item_draggridview, new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                LogUtils.i("1city-->"+item.getName());
                SPUtil.getInstance().setCurrentCity(item.getName());
                SPUtil.getInstance().setCurrentCityId(item.getId());
                SPUtil.getInstance().setCurrentCounty(item);
                SPUtil.getInstance().setCurrentCountryPosition(position);
                SPUtil.getInstance().setIsLarge(item.getIslarge());
                CurrentCityEventForMainAndZiXun event2 = new CurrentCityEventForMainAndZiXun();
                EventBus.getDefault().post(event2);
                CurrentSecondCityEvent event = new CurrentSecondCityEvent();
                event.setPosition(position);
                LogUtils.i("2city-->"+item.getChild().get(position).getName());
                event.setCurrentCity(item.getChild().get(position).getName());
                EventBus.getDefault().post(event);
                activity.finish();
            }
        });
    }
}
